//
//  VehiclePlanDetailViewController.m
//  Runone
//
//  Created by runone02 on 16/10/27.
//  Copyright © 2016年 runone. All rights reserved.
//   用车计划

#import "VehiclePlanDetailViewController.h"
#import "RequestGinsengModel.h"
#import "RequestOutginseng.h"
#import "RequestHelper.h"
#import "AppDelegate.h"
#import "MJExtension.h"
#import "IntVclDrivedRecordInfo.h"
#import "VehiclePlanCell.h"
#import "UIView+Addition.h"


@interface VehiclePlanDetailViewController ()

@property (nonatomic, strong) NSArray *dataArray;

@property (nonatomic, strong)  VehiclePlanCell *prototypeCell;

@property (strong, nonatomic) IntVclDrivedRecordInfo *model;

@end

static NSString *cellID = @"Cell";
@implementation VehiclePlanDetailViewController


#pragma    --------用车计划


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.navigationController.navigationBar.hidden = NO;
    [self configNavigationBar];
    
    [self configTableview];
    [self requestData];
}


- (void) configNavigationBar {
    self.tabBarController.tabBar.hidden = NO;
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:(68.0 / 255) green:(169.0 / 255) blue:(213.0 / 255) alpha:1.000]];
    self.navigationController.navigationBar.tintColor=[UIColor whiteColor];
    
    UIBarButtonItem *backbutton = [[UIBarButtonItem alloc]init];
    backbutton.title = @"车辆信息";
    self.navigationItem.backBarButtonItem = backbutton;
    
    UILabel *titleLabel  = [[UILabel alloc] init];
    titleLabel.size      = CGSizeMake(100, 30);
    titleLabel.text      = @"用车计划";
    titleLabel.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = titleLabel;
}

- (void) configTableview {
    self.tableView.bounces            = NO;
    self.tableView.separatorStyle     = UITableViewCellSeparatorStyleNone;
    _prototypeCell = [self.tableView dequeueReusableCellWithIdentifier:cellID];
    [self.tableView registerNib:[UINib nibWithNibName:@"VehiclePlanCell" bundle:nil] forCellReuseIdentifier:cellID];
}

-(void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden=YES;
}


//刷新数据
- (void) requestData {
    RequestHelper *requestHelper = [[RequestHelper alloc] init];
    RequestGinsengModel *IntVclDrivedRecordModel = [[RequestGinsengModel alloc] init];
    IntVclDrivedRecordModel.URL                  = GetIntVclBaseInfo;
    IntVclDrivedRecordModel.DataValue            = @"";
    IntVclDrivedRecordModel.UpdatedTime          = @"2012-01-12 12:00:00";
    IntVclDrivedRecordModel.SystemCode           = @"GuangleHighway";
    IntVclDrivedRecordModel.MethodName           = @"GetIntVclDrivedRecordInfo";
    requestHelper.block = ^(RequestOutginseng *requestOutginseng,id dataValueModel) {
        NSLog(@"%@",requestOutginseng.DataValue);
        _dataArray = [IntVclDrivedRecordInfo mj_objectArrayWithKeyValuesArray:requestOutginseng.DataValue];
        [self.tableView reloadData];
    };
    [requestHelper RequestGinsengModel:IntVclDrivedRecordModel andPushController:self];
}
#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    VehiclePlanCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    IntVclDrivedRecordInfo *model = _dataArray[indexPath.row];
    cell.intRecordModel = model;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    IntVclDrivedRecordInfo *model = _dataArray[indexPath.row];
    return  model.vclPlanCellH;
}




@end
